package com.googlecode.projects.tests;

import java.sql.*;

/**
 * The purpose of this class 'JDBCCreateTable.java' is to test that the
 * applications code can successfully create a new table in a database.
 * 
 * @author Sean
 * 
 */
public class JDBCDropTable {

	/**
	 * Create a main method to run the program.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		/**
		 * Create a new connection and set it to null.
		 */
		Connection connection = null;

		/**
		 * Create a new string to hold the name of the database.
		 */
		String database = "jdbc:derby:/DerbyDB/AssetDB";

		/**
		 * Create a new string to hold the name of the database driver.
		 */
		String databaseDriver = "org.apache.derby.jdbc.EmbeddedDriver";

		/**
		 * Create a string that holds the SQL query.
		 */
		String dropTable = "DROP TABLE TEST";

		/**
		 * Try and add the table to the database.
		 */
		try {
			Class.forName(databaseDriver).newInstance();
			connection = DriverManager.getConnection(database);
			try {
				Statement statement = connection.createStatement();
				statement.executeUpdate(dropTable);
				System.out.println("Table successfully removed!!!");
			} catch (SQLException s) {
				System.out.println("No table TEST to be removed!!!");
			}
			connection.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
